package com.unity3d.eventbus;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView=findViewById(R.id.textView);
        /*注册EventBus,只用注册才能收到消息*/
        EventBus.getDefault().register(this);
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
//            跳转到Activity2中
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,MainActivity2.class);
                startActivity(intent);
            }
        });
    }
    /*定义一个public void的方法接收其他的Activity通过eventbus发出的消息*/
    @Subscribe(threadMode = ThreadMode.MAIN)/*并且设置接收方法的线程，这里在主线程，可以通过这个方法实现线程切换*/
    public void message(String s){
        textView.setText(s);
    }

}


// VideoView videoView;

// videoView=findViewById(R.id.text);
//         videoView.setVideoURI(Uri.parse("http://121.4.44.56/a2.mp4"));
//         MediaController mediaController = new MediaController(this);
//         videoView.setMediaController(mediaController);
//videoView.start();